package com.rising.face.ali.bishi.countAward;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author: rising
 * @Description:
 * #有n个人参加编程，赛后每个人都的到一个分数；现在所有人排成一圈（第一个和第n个相邻），领取奖品，要求“：
 * #1.如果某个的分数比左右的人高，那么奖品的数量也要比左右的人多，
 * #2.每个人至少得到一个奖品；问最少应该准备多少个奖品。
 * @Date: create in 2021/2/28 16:41
 */
public class ShareAward {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        //人数
        System.out.print("请输入总人数：");
        int people = sc.nextInt();
        int[] score = new int[people];
        //保存分数
        System.out.println("请输入每个人的分数（输入一个回车一下）：");
        List<Integer> scoreList = new LinkedList<>();
        for (int i = 0; i < people; i++) {
            int scoreByConsole = sc.nextInt();
            score[i] = scoreByConsole;
            scoreList.add(scoreByConsole);
        }

        System.out.println("测试案例【总人数：" + people + "，分数：" + scoreList + "】");
        int res1 = countAward(score);
        System.out.println("总奖品数：" + res1);
    }

    private static int countAward(int[] score) {
        int res1 = 0;
        int[] award = new int[score.length];
        //顺序遍历一圈，
        for (int i = 0; i < score.length; i++) {
            //当i=0，左边则是最后一个
            if (i == 0) {
                if (score[i] > score[score.length - 1] && score[i] > score[1]) {
                    award[i] = 2;
                } else {
                    award[i] = 1;
                }
                continue;
            }
            //当i = score.length - 1，则右边是第一个
            if (i == score.length - 1) {
                if (score[i] > score[i - 1] && score[i] > score[0]) {
                    award[i] = 2;
                } else {
                    award[i] = 1;
                }
                continue;
            }
            //其他就是在圈里面
            if (score[i] > score[i - 1] && score[i] > score[i + 1])
                award[i] = 2;
            else
                award[i] = 1;
        }

        for (int i = 0; i < award.length; i++) {
            res1 += award[i];
        }
        return res1;
    }

}
